<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/jquery.js"></script>
</head>

<body>
    <button>获取1</button>
</body>
<!-- <script>
    var n, m
    $(function () {
        $('button').click(function () {
            new Promise((resolve, reject) => {
                setTimeout(() => {
                    n = 1
                    console.log('定时器执行完成了');
                    resolve(n)
                }, 1000)
            })
                .then((res) => {
                    console.log('请求2开始');
                    return new Promise((resolve, reject) => {
                        $.ajax({
                            url: 'https://liu.zzgoodqc.cn/gaode?n=' + res,
                            dataType: 'json',
                            success: function(data){
                                console.log('请求2完成')
                                n = 666
                                resolve(m)
                            },
                        })
                    })
                })
                .then(function(res){
                    console.log('请求3开始');
                    $.ajax({
                        url: 'https://liu.zzgoodqc.cn/gaode?res=' + res,
                        dataType: 'json',
                        success: function(data){
                            console.log('请求3完成')
                        }
                    })
                })
        })
    })
</script> -->
 
<script>
    const p = new Promise((resolve, reject) => {
        $.ajax({
            method: 'GET', 
            url: 'https://liu.zzgoodqc.cn/promise1',
            dataType: 'json',
            success: function (res) {
                console.log(res.data);
                resolve(res.data.url)
            }
        })
    })
    p.then(
        (url) => {
            return new Promise((resolve, reject) => {
                $.ajax({
                    method: 'POST',
                    url: `https://liu.zzgoodqc.cn${url}`,
                    dataType: 'json',
                    success: function (res) {
                        console.log(res.data);
                        reject(res.data.url)
                    }
                })
            })
        },
    )
        .then(
            () => { },
            (url) => {
                return new Promise((resolve, reject) => {
                    $.ajax({
                        method: 'GET',
                        url: `https://liu.zzgoodqc.cn${url}`,
                        dataType: 'json',
                        success: function (res) {
                            console.log(res.data);
                            resolve(res.data.url)
                        }
                    })
                })
            })
        .then((url) => {
            return new Promise((resolve, reject) => {
                $.ajax({
                    method: 'POST',
                    url: `https://liu.zzgoodqc.cn${url}`,
                    dataType: 'json',
                    success: function (res) {
                        console.log(res.data);
                        resolve(res.data.url)
                    }
                })
            })
        })
</script>

</html>